<?php
/**
 * Created by PhpStorm.
 * User: xpz
 * Date: 2021/5/18
 * Time: 12:49
 */
namespace app\admin\controller\chat;

use app\common\controller\Backend;
use fast\Tool;

class Lists extends Backend
{
    protected $model = null;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('ChatMessage');
    }

    public function index(){
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams('color');
            $total = $this->model
                ->where($where)
                ->order($sort, $order)
                ->count();
            $list = $this->model
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
            $result = array("total" => $total, "rows" => $list);


            return json($result);
        }
        return $this->view->fetch();
    }

    public function deploy(){
        $id = $this->request->param('ids');
        if(empty($id)){
            $this->error('请选择要获取的对象！');
        }
        $messageInfo = $this->model->where(['id'=>$id])->find();
        if(empty($messageInfo['id'])){
            $this->error(__('所选对象不存在！', ''));
        }
        //http://jkb.lishiketang.com/kf/3D7A2972-4567-C3C5-5F74-A3733B3103A6/oG4_vH6_yYzIIq1q4uRsald/
        $token = Tool::en_token($messageInfo['user_id'],$messageInfo['company_id']);
        $url = Tool::getDomain()."/kf/".$messageInfo['uuid']."/".$token;
        return $this->success("ok","",$url);
    }
}